<?php

namespace app\controller\v1\admin;

use app\BaseController;
use app\common\Send;
use app\service\TaskOrderService;
use app\utils\TaskOrderEmun;
use think\App;
use think\Request;

class TaskOrder extends BaseController
{
    use Send;
    private $taskOrderService;
    public function __construct(App $app, Request $request){
        parent::__construct($app);
        $this->taskOrderService = new TaskOrderService();
    }

    public function index(){
        $params = $this->request->param();
        $result = $this->taskOrderService->list($params);
        return self::success($result);
    }

    //查看状态
    public function status()
    {
        return self::success(TaskOrderEmun::taskOrderStatusText());
    }


    public function save(){
        $params = $this->request->param();
        $result = $this->taskOrderService->save($params);
        return self::success($result);
    }

    /**
     * 批量更新状态
     *
     * 该方法用于处理批量更新订单状态的请求它从请求中获取参数，
     * 调用任务订单服务中的相应方法进行处理，并返回成功的结果
     *
     * @return mixed 返回成功结果的响应
     */
    public function batchUpdateStatus()
    {
        // 获取请求参数
        $params = $this->request->param();

        // 调用服务层方法执行批量更新状态
        $result = $this->taskOrderService->batchUpdateStatus($params);

        // 返回成功结果
        return self::success($result);
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request, $id)
    {
        $data = $request->param();
        $result = $this->taskOrderService->update($id, $data);
        return self::success($result);
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        $result = $this->taskOrderService->delete($id);
        return self::success($result);
    }

}
